package com.siwei.mes.entity.experiment;

import cn.dev33.satoken.stp.StpUtil;
import com.siwei.mes.common.validator.AddGroup;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;
import java.util.List;


/**
 * 打印记录(ExperimentPrintRecord)实体类
 *
 * @author linzi
 * @since 2024-07-27 18:22:11
 */
@Data
@Accessors(chain = true)
@Table(name = "pk_experiment_print_record")
@ApiModel(value = "ExperimentPrintRecord", description = "打印记录")
public class ExperimentPrintRecord implements Serializable {
    private static final long serialVersionUID = -23236529042402804L;
    /**
     * 主键id
     */
    @Id
    @ApiModelProperty(value = "打印记录主键ID", name = "id")
    private Long id;
    /**
     * 试验委托id
     */
    @Column(name = "experiment_id")
    @ApiModelProperty(value = "试验委托id", name = "experimentId")
    private Long experimentId;
    /**
     * 打印人
     */
    @Column(name = "print_user_id")
    @ApiModelProperty(value = "打印人", name = "printUserId")
    private Long printUserId;
    /**
     * 打印时间
     */
    @Column(name = "print_time")
    @ApiModelProperty(value = "打印时间", name = "printTime")
    private Date printTime;
    /**
     * 打印数据来源json
     */
    @Column(name = "print_json")
    @ApiModelProperty(value = "打印数据来源json", name = "printJson")
    private String printJson;
    /**
     * 打印html
     */
    @Column(name = "print_html")
    @ApiModelProperty(value = "打印html", name = "printHtml")
    private String printHtml;

    @Transient
    @ApiModelProperty(value = "多个试验委托id集合")
    @NotNull(groups = {AddGroup.class}, message = "试验委托id集合为空")
    private List<Long> experimentIdList;

    public ExperimentPrintRecord init(boolean isCreate) {
        if (isCreate) {
            this.setPrintUserId(StpUtil.isLogin() ? StpUtil.getLoginIdAsLong() : null).setPrintTime(new Date());
        }
        return this;
    }
}
